	\section{Language Architecture}
	\label{section:LanguageArchitecture}			
		In the following section we give a description of the main features, which we would like to implement in our language\cite{bogfraspo}. For a complete documentation see appendix \ref{appenix:documentation}.
			
		One of the key features of our language, that differs from most popular languages such as C, is that CLUBs is designed for users with very limited or no programming experience. With this in mind our language will, among other things, support the option to declare a board, pieces, action etc.  in any order. Which contradicts from most programming languages. In languages like C the code inside a function can only call a function that is declared above, a constraint that we believes makes it difficult for novice programmers, this will not be the case in CLUBs.
			
		\subsection{The Code Structure}
				While there are a lot of possible ways to structure the code, we decided to use a neasted block structure. When working with a block structure there are several ways to define a start and end of a block. The most common in modern language are the curly brackets $\{$ when a block starts and $\}$ when a block ends. 
				
				In listing \ref{TheCodeStructure:CurlyBracketsandBeginEndexample} is an example of how the keywords \textbf{begin} and \textbf{end} or curly brackets can be added for readability.
				
				\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords= {using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool, begin, end},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Curly Brackets and Begin End example},
				label={TheCodeStructure:CurlyBracketsandBeginEndexample}]
				//Curly Brackets 
				function Main()
				{
					int i;
					//Some code which is going to be executed
					
					if(i=100)
					{
						//Some code which is going to be executed
					}
					
				}
				//Begin End
				function Main()
				begin
					int i;
					//Some code which is going to be executed
					
					if(i=100)
					begin
						//Some code which is going to be executed
					end
				end
				\end{lstlisting}
				For CLUBs we decided to implement the curly brackets. There is an upside and a downside to this choice. While using curly brackets makes the code more structured, and easier to create an overview. 
				
				By excluding the begin and end statement we make the code less understandable for total beginners. This is consistent with our design goals, since we want to minimize the over usage of keywords and to make the code more readable.
				
			\subsection{Tokens}
				For the CLUBs language we decided to use a lot of tokens which are used in languages like C\# and java. Like the end of line token for example "$;$" or the assignment operator "$=$". We also decided to use the same style to declare variables, function and class names with their different syntax. Classes are strictly lower case while functions and variables can be camelcase, lowercase or uppercase.
				In the EBNF in section \ref{EBNF} there all the tokens currently used in CLUBs, they can also be found in appendix \ref{chapter::Tokens}.
				
			\subsection{Variables}
			Our base types in CLUBs are Boolean, String and Integer.
			A Boolean can have two different values, \textit{true} or \textit{false}.
			\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of Boolean},]		
bool myBool = true;
bool myBool = false;
				\end{lstlisting}
			A string consists of a quotation mark any number of characters and an end quotation mark.
			\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of String},]		
string myString = "This is a string";
				\end{lstlisting}
			An integer can be any integral number like $5$ or $24684$.
			\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of Int},]		
int myInt1 = "5";
int myInt1 = "24684";
				\end{lstlisting}
				These three base type are important for our laungage for different reasons. First boolean, most commonly used in \textit{if} or \textit{while} statments and as the result returned by an action. We could just use integers like in \textit{C}, but in our oppinion its more readably with useing the keyword \textit{true} and \textit{false}. 
				Now integers are also important since these are necessary to do mathmatics, and they are also useful in \textit{for} loops.
				Strings in CLUBs are used to define a path to a file\footnote{An example of this can be found in appendix \ref{appenix:documentation} in the extended example section \ref{appenix:documentation:ExtendedExample}}.
	
			\subsection{Function and Class declaration}
				CLUBs uses the concept of classes and functions. The CLUBs interpreter has build-in functionality which uses keywords to fillout predefines schemes or classes. This predefined functionality is used to make implementation of ideas much faster. The downside to this approach is that limitations for developer can occur. An example of Tic-Tac-Toe can be found in listing \ref{FunctionandClassdeclaration:CodeExampleofBoardandCell}.
				
				\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of Board and Cell},
				label={FunctionandClassdeclaration:CodeExampleofBoardandCell}]		
//Class: game
game
{
	cell MainCell
	{
		MaxPieces = 2; //variable	
	}
}
board MainBoard
{
	CellType = MainCell;
	//Creating the board from the function
	MakeRect(6,6);
}

piece P1Piece
{
	//variable declaration of the icon of the player, other attributes of the piece P1piece can be change too if implemented
	Icon = "avatar1.png" ;
}
				\end{lstlisting}
			%The laungage doesn't support class directly. But support the ability to declare board, piece etc. in the global scope. These types with predefined properties are used like classes in the sense that they used to describe an object contained in a board game.

			Function are also declared in the global scope. They do not contain predefined properties and do not describe an object. In our programming language it is used to describe an automated event or any form of calculation which require some input. For most beginners this would most likely be automated events. Therefore we decided on naming functions \textbf{action}.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of action},]		
//Class: game
game
{
	action MyAction gives int
	{
		//automated events goes here.
		int first = 1;
		int secound = 2;
		int result;
		result = first + second;
		give(result);
	}
}
				\end{lstlisting}
			This action returns the integer 3. Another example of when these actions are useful is when we need to check if a player has won. This can be done by making an action CheckWin and then implement the relevant code. In this case we check for four in a row. Which is in another action later on.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of Win Action},]		
action CheckWin
{
	if (ThreeInARow(MainBoard, CurrentPlayer->MainPiece, 3, 3))
	{
		Win(CurrentPlayer);
		EndGame();
	}
}
\end{lstlisting}
	The actual part that makes the game stop is the action \textit{EndGame}, this is implemented because in some games more then one player can win before the game is finished. The action \textit{Win} tells the game that a specific player has won.
	The next example, \textit{ThreeInARow}, is slightly longer. We have only put a small part of it in the report\footnote{the action can be found in LineFunction.clubs in the implementation files see appendix \ref{appendix:readme}}. \textit{ThreeinARow} takes some input first the board then the currentplayers, main piece and the width and length of the board. We then run through all cells in the board, by using the build in action \textit{GetCellAt(x,y)} to get a specific cell. When we need to compare, if the cell contains a piece belonging to the current player, we use the build in action \textit{GetFirstPiece(cell)} to get the first piece placed on that cell. If they all match the player wins, and we give true, else we give false.
		
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of ThreeInARow},]		
action ThreeInARow gives bool takes board b, piece p, int width, int height
{
	int x = 0;
	int y;
	cell c1;
	cell c2;
	cell c3;
	while (not (x is width))
	{
		y = 0;
		while (not (y is (height)))
		{
			c1 = GetCellAt(x,y);
			c2 = GetCellAt(x+1,y);
			c3 = GetCellAt(x+2,y);
			if (GetFirstPiece(c1) is p)
			{
				if (GetFirstPiece(c2) is p)
				{
					if (GetFirstPiece(c3) is p)
					{
						give(true);
					}
				}
			}
			...
			//The check on the other angels goes here.
			y = y + 1;
		}
		x = x + 1;
	}
	give(false);
}
\end{lstlisting}		


\subsection{Rounds and Turns}
An important aspect of this programming language is the ability to declare round, and keep looping these rounds until the game is finished. 
In CLUBs this will be possible by using the action \textit{UseRound(ARound)} this will active the round \textit{ARound} a make it loop until the game is finished. It is possible to change to another round if desired by using the action \textit{UseRound(ARound)} again. The \textit{start} action is used to begin the game, it is called first thing when the game starts to initialize the code.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of UseRound},]		
start
{
	UseRound(MainRound);
}
round MainRound
{
	// Looping until the game is finished.

}
\end{lstlisting}

Inside a round it is possible to define different turns. This is useful because one of the parameters a turn takes is a player, and because a lot of games have identical round for more than one player, this can save a lot of code redundancy.
\begin{lstlisting}[basicstyle=\small\sffamily, 
				keywords={using, library, game, action, gives, takes, start, if, check, case, while, for, board, cell, piece, player, round, turn, int, string, true, false, bool},
				keywordstyle={\color{blue}},
				comment={[l]{//}}, morecomment={[s]{/*}{*/}}, commentstyle=\itshape,
				columns={[l]flexible}, numbers=left, numberstyle=\tiny,
				frameround=fftt, frame=shadowbox, captionpos=b,
				caption={Code Example of turn},]	
round MainRound
{
	DoTurn(MainTurn, Player1);
	DoTurn(MainTurn, Player2);
}
turn MainTurn
{
	//getting the currentpiece
	piece currentPiece = CurrentPlayer->MainPiece;
}
\end{lstlisting}

A more thorough explentation of all the build in action along with examples of how to make games can be found in appendix \ref{appenix:documentation}.
	
